#!/usr/bin/env python3
# funny helper to try echo_server.cpp
# use https://github.com/haraldh/rust_echo_bench for further testingc
import socket

HOST = "127.0.0.1"  # The server's hostname or IP address
PORT = 9982  # The port used by the server

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    start = 1
    junks = bytes(
        "HFLSDNGKJDSGDSKL:NGEJNGOSDHGLKDSGJWE:LFHODSGNSDLGHDGLKSDJKGJDKSJGKSDGJKSDHFLSDNGKJDSGDSKL:NGEJNGOSDHGLKDSGJWE:LFHODSGNSDLGHDGLKSDJKGJDKSJGKSDGJKSDHFLSDNGKJDSGDSKL:NGEJNGOSDHGLKDSGJWE:LFHODSGNSDLGHDGLKSDJKGJDKSJGKSDGJKSDHFLSDNGKJDSGDSKL:NGEJNGOSDHGLKDSGJWE:LFHODSGNSDLGHDGLKSDJKGJDKSJGKSDGJKSDHFLSDNGKJDSGDSKL:NGEJNGOSDHGLKDSGJWE:LFHODSGNSDLGHDGLKSDJKGJDKSJGKSDGJKSDHFLSDNGKJDSGDSKL:NGEJNGOSDHGLKDSGJWE:LFHODSGNSDLGHDGLKSDJKGJDKSJGKSDGJKSDHFLSDNGKJDSGDSKL:NGEJNGOSDHGLKDSGJWE:LFHODSGNSDLGHDGLKSDJKGJDKSJGKSDGJKSDHFLSDNGKJDSGDSKL:NGEJNGOSDHGLKDSGJWE:LFHODSGNSDLGHDGLKSDJKGJDKSJGKSDGJKSDHFLSDNGKJDSGDSKL:NGEJNGOSDHGLKDSGJWE:LFHODSGNSDLGHDGLKSDJKGJDKSJGKSDGJKSDHFLSDNGKJDSGDSKL:NGEJNGOSDHGLKDSGJWE:LFHODSGNSDLGHDGLKSDJKGJDKSJGKSDGJKSDHFLSDNGKJDSGDSKL:NGEJNGOSDHGLKDSGJWE:LFHODSGNSDLGHDGLKSDJKGJDKSJGKSDGJKSDHFLSDNGKJDSGDSKL:NGEJNGOSDHGLKDSGJWE:LFHODSGNSDLGHDGLKSDJKGJDKSJGKSDGJKSDHFLSDNGKJDSGDSKL:NGEJNGOSDHGLKDSGJWE:LFHODSGNSDLGHDGLKSDJKGJDKSJGKSDGJKSDHFLSDN*(KJDS*(DSKL:N*(EJN*(OSDH*(LKDS*(JWE:LFHODS*(NSDL*(HD*(LKSDJK*(JDKSJ*(KSD*(JKSDHFLSDN*(KJDS*(DSKL:N*(EJN*(OSDH*(LKDS*(JWE:LFHODS*(NSDL*(HD*(LKSDJK*(JDKSJ*(KSD*(JKSDHFLSDN*(KJDS*(DSKL:N*(EJN*(OSDH*(LKDS*(JWE:LFHODS*(NSDL*(HD*(LKSDJK*(JDKSJ*(KSD*(JKSDHFLSDN*(KJDS*(DSKL:N*(EJN*(OSDH*(LKDS*(JWE:LFHODS*(NSDL*(HD*(LKSDJK*(JDKSJ*(KSD*(JKSDHFLSDN*(KJDS*(DSKL:N*(EJN*(OSDH*(LKDS*(JWE:LFHODS*(NSDL*(HD*(LKSDJK*(JDKSJ*(KSD*(JKSDHFLSDN*(KJDS*(DSKL:N*(EJN*(OSDH*(LKDS*(JWE:LFHODS*(NSDL*(HD*(LKSDJK*(JDKSJ*(KSD*(JKSDHFLSDN*(KJDS*(DSKL:N*(EJN*(OSDH*(LKDS*(JWE:LFHODS*(NSDL*(HD*(LKSDJK*(JDKSJ*(KSD*(JKSD",
        'utf-8')
    index = 0
    s.connect((HOST, PORT))
    print("connected, len is ", len(junks))
    s.sendall(junks)
    print("sent")
    data = s.recv(len(junks) * 3)
    print(f"recv:{data!r}")
    while ((len(data) < len(junks) * 3)):
        now = s.recv(len(junks))
        if (len(now) == 0):
            break
        data += now
        print(f"recv again, {data!r}")
    if (junks.decode('utf-8') != data.decode('utf-8')):
        print('fuck, total: ', len(data))
    else:
        print('Thankyou, you are correct, toal recv: ', len(data))
